package com.xnx.contorller;

import com.xnx.bean.BaseRespVo;
import com.xnx.bean.QueryBO;
import com.xnx.bean.User;
import com.xnx.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.sql.DataSource;
import java.util.List;

@RestController
@RequestMapping("user")
public class UserContorller {

    @Autowired
    UserService userService;

    @Autowired
    DataSource dataSource;
    @RequestMapping("hello")
    public BaseRespVo hello(){
        return BaseRespVo.ok("hello world");
    }


    @RequestMapping("list")
    public BaseRespVo list(String username, String mobile, String sort, String order, Integer limit) {

        QueryBO queryBO = new QueryBO(username, mobile, sort, order, limit);
        List<User> users = userService.selectUser(queryBO);
        return BaseRespVo.ok(users);
    }

    @RequestMapping("add1")
    public BaseRespVo add1(User user){
        int code = userService.add(user);
        if (code == 200){
            return BaseRespVo.ok();
        }else {
            return BaseRespVo.fail("注册失败");
        }
    }

    @RequestMapping("add2")
    public BaseRespVo add2(@RequestBody User user){
        int code = userService.add(user);
        if (code == 200){
            return BaseRespVo.ok();
        }else {
            return BaseRespVo.fail("注册失败");
        }
    }






}
